<template>
    <div class="photoinfo-container">
        <h3>{{ photoInfo.pnTitle}}</h3>
        <p class="subtitle">
            <span>发表时间：{{ photoInfo.createTime | dateFormat}}</span>
            <span>点击：{{ photoInfo.clickNumber }} 次</span>
        </p>

        <hr>
        <div class="content" v-html="photoInfo.pnNews">
        </div>
        <!-- 缩略图区域 -->
        <div class="thumb">
            <vue-preview :slides="list" @close="handleClose"></vue-preview>
        </div>
        
        <!-- 图片内容区域 -->
        

        <!-- <div class="content" v-for="(item,i) in pictureList" :key="i">
            <img :src="'http://'+item" alt="">
        </div> -->
        <!-- 放置现成的评论组件 -->
        <cmt-box :pnId="id"></cmt-box>
    </div>
</template>

<script>
// 1. 导入评论子组件
import comment from '../subocomponents/PhotoComment.vue'

export default {
    data() {
        return{
            id: this.$route.params.id, // 从路由中获取到的图片id
            photoInfo: {}, // 图片详情
            pictureList: [],
            thumbs: [],
            list: [],
        }
    },
    created() {
        this.getPhotoInfo();
    },
    methods: {
        getPhotoInfo(){
            // 获取图片详情
            this.$http.get('front/photos/news/'+this.id).then(result =>{
                if(result.body.code===1){
                    this.photoInfo = result.body.data;
                    this.pictureList = result.body.data.pictureList;
                    this.thumbs = result.body.data.thumbList;
                    this.getThumbs();
                }
            })
        },
        getThumbs(){
            var thumbs = this.thumbs
            var list = []
            this.pictureList.forEach(function(item,index){
                var thumb = {
                    src: 'http://'+item,
                    msrc: 'http://'+thumbs[index],
                    w: 600,
                    h: 500
                }
                list.unshift(thumb)
            })
            this.list = list;
        },
        handleClose () {
        console.log('close event')
        }
    },
    components:{ // 注册子组件
        'cmt-box': comment
    }
}
</script>

<style lang="scss" scoped>
    .photoinfo-container{
        padding: 3px;
        h3{
            color: #26A2FF;
            font-size: 15px;
            text-align: center;
            margin: 15px 0;

        }
        .subtitle{
            display: flex;
            justify-content: space-between;
            font-size: 13px;
            color: #000000;
        }

        .content{
            font-size: 13px;
            line-height: 30px;
        }
        .thumb{
            img{
                height: 250px;
                width: 250px;
                margin: 10px;
                box-shadow: 0 0 8px #999
            }
        }
    }
</style>